import { useBaseStore } from '@/stores/useBaseStore.js'
import router from '@/router/index.js'
let baseStore = null
const authObj = {
  find: 1,
  add: 2,
  update: 4,
  delete: 8,
}

export default {
  mounted(el, binding) {
    if (baseStore == null) {
      baseStore = useBaseStore()
    }
    let path = router.currentRoute.value.path
    let arr = baseStore.menus.filter(function (item) {
      return item.right_path == path
    })
    if (arr.length == 0) {
      return
    }
    let count = 0
    for (let item of binding.value) {
      count += authObj[item]
    }

    if ((arr[0].right_function & count) === 0) {
      let parentNode = el.parentNode
      if (parentNode == null) {
        el.style.display = 'none'
        return
      }
      parentNode.removeChild(el)
    }
  },
}
